package com.example.progressrecord.leancloud

import android.os.Parcelable
import cn.leancloud.AVObject
import io.reactivex.functions.Consumer
import kotlinx.android.parcel.Parcelize
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import java.util.*

@Parcelize
class ProgressInfo() :Parcelable {

    private lateinit var avObject: AVObject

    companion object {
        const val NAME = "ProgressRecord"
        const val TIME_KEY = "Time"
        const val CREATININE_KEY = "Creatinine"
        const val URINE24H_VOLUME_KEY = "Urine24hVolume"
        const val URINE_PROTEIN24H_CONCENTRATION_KEY = "UrineProtein24hConcentration"
        const val REMARK_KEY = "remark"
    }

    init {
        avObject = AVObject(NAME)
    }



    constructor(
        time: Date,
        creatinine: Float,
        urine24hVolume: Float,
        urineProtein24hConcentration: Float,
        remark: String
    ) : this() {
        this.time = time
        this.creatinine = creatinine
        this.urine24hVolume = urine24hVolume
        this.urineProtein24hConcentration = urineProtein24hConcentration
        this.remark = remark
    }

    var time: Date? = null
        set(value) {
            avObject.put(TIME_KEY, value)
            field = value
        }

    var creatinine: Float? = null
        set(value) {
            avObject.put(CREATININE_KEY, value)
            field = value
        }

    //2.4L
    var urine24hVolume: Float? = null
        set(value) {
            avObject.put(URINE24H_VOLUME_KEY, value)
            field = value
        }

    //1.5mg/L
    var urineProtein24hConcentration: Float? = null
        set(value) {
            avObject.put(URINE_PROTEIN24H_CONCENTRATION_KEY, value)
            field = value
        }

    var urineProtein24h: Float? = null
        get() = urineProtein24hConcentration?.let { urine24hVolume?.times(it) }

    var remark: String? = null
        set(value) {
            avObject.put(REMARK_KEY, value)
            field = value
        }

    fun getObj() = avObject


}